package date0708pm;

import java.sql.Date;
import java.sql.PreparedStatement;
import java.time.LocalDate;
import java.util.Arrays;

import cn.edu.ecut.util.DatabaseType;
import cn.edu.ecut.util.JdbcHelper;

public class JdbcTest30 {

	public static void main(String[] args) throws Exception {

		JdbcHelper h = JdbcHelper.getInstance( DatabaseType.MYSQL );
		
		PreparedStatement ps = h.prepare( "INSERT INTO t_users ( name , gender , birthdate , id ) VALUES ( ? , ? , ? , ? )" );
		System.out.println( ps );
		
		ps.setString( 1 ,  "张三丰" );
		ps.setString( 2 , "男" );
		ps.setDate( 3 , Date.valueOf( LocalDate.of( 1312 , 10 , 20) ) );
		ps.setInt( 4 ,  1001 );
		ps.addBatch(); // 将新设置好的参数值添加到一个批次中
		
		ps.setString( 1 ,  "杨过" );
		ps.setString( 2 , "男" );
		ps.setDate( 3 , Date.valueOf( LocalDate.of( 1300 , 5 , 12 ) ) );
		ps.setInt( 4 ,  1002 );
		ps.addBatch(); // 将新设置好的参数值添加到一个批次中
		
		ps.setString( 1 ,  "小龙女" );
		ps.setString( 2 , "男" );
		ps.setDate( 3 , Date.valueOf( LocalDate.of( 1290 , 2 , 22 ) ) );
		ps.setInt( 4 ,  1003 );
		ps.addBatch(); // 将新设置好的参数值添加到一个批次中
		
		int[] counts = ps.executeBatch(); //批量执行
		System.out.println( Arrays.toString( counts ) );
		
		h.close( ps );
		h.release();

	}

}
